<?php 
class user_admin_type
{ 
	function admin_type() 
	{ 
		global $mysql_conn,$v_file;
		$sql = "SELECT * from `user_type` ";
		$result = mysql_query($sql,$mysql_conn);
		while(@$row=mysql_fetch_array($result)) {
			$type_id = $row['type_id'];
			$type_name = $row['type_name'];
			$type_bot_num = $row['type_bot_num'];
			$type_pay = $row['type_pay'];
			$type_pay_bot = $row['type_pay_bot'];
			$userlist .= "<tr><td>";
			$userlist .= "    <input type='checkbox' class='i-checks' name='input[]'>";
			$userlist .= "</td>";
			$userlist .= "<td>".$type_id."</td>";
			$userlist .= "<td>".$type_name."</td>";
			if (empty($type_bot_num)) {
				$userlist .= "<td>无限制</td>";
			} else {
				$userlist .= "<td>".$type_bot_num." 个 </td>";
			}
			if (empty($type_bot_num)) {
				$userlist .= "<td>无限制</td>";
			} else {
				$userlist .= "<td>".$type_pay." 积分 / 月</td>";
			}
			if (empty($type_pay_bot)) {
				$userlist .= "<td>无限制</td>";
			} else {
				$userlist .= "<td>".$type_pay_bot." 积分 / 个</td>";
			}
			$userlist .= "<td>";
			$userlist .= "<a href='#' class='btn btn-white btn-xs' onClick='admin_type_edit(".$type_id.");'><i class='fa fa-edit'></i> 编辑 </a>";
			$userlist .= "<a href='#' class='btn btn-white btn-xs' onClick='admin_type_del(".$type_id.");'><i class='fa fa-trash-o'></i> 删除 </a>";
			$userlist .= "</td></tr>";
		}
		require($v_file); 
	}
	function admin_type_add_do() 
	{ 
		global $mysql_conn;
		$new_user_type = $_POST['new_user_type'];
		$sql = "SELECT * from `user_type` WHERE `type_name` = '".$new_user_type."'";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		if (empty($row)) {
			$sql="INSERT INTO user_type (type_name) VALUES ('$new_user_type')";
			$result = mysql_query($sql,$mysql_conn);
			@$row = mysql_fetch_array($result);
			echo "2";//会员类型添加成功
		} else {
			echo  "1";//会员类型已存在
		}
	}
	function admin_type_edit() 
	{ 
		global $mysql_conn,$v_file;
		$type_id = $_GET['type_id'];
		$sql = "SELECT * from `user_type` WHERE `type_id` = '".$type_id."'";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		$type_name = $row['type_name'];
		$type_bot_num = $row['type_bot_num'];
		$type_pay = $row['type_pay'];
		$type_pay_bot = $row['type_pay_bot'];
		require($v_file);
	}
	function admin_type_edit_do() 
	{ 
		global $mysql_conn;
		$type_id = $_POST['type_id'];
		$type_name = $_POST['type_name'];
		$type_bot_num = $_POST['type_bot_num'];
		$type_pay = $_POST['type_pay'];
		$type_pay_bot = $_POST['type_pay_bot'];
		$sql = "UPDATE `user_type` SET `type_name` = '".$type_name."',`type_bot_num` = '".$type_bot_num."',`type_pay` = '".$type_pay."',`type_pay_bot` = '".$type_pay_bot."' WHERE `type_id` ='".$type_id."';";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		echo "1";
	}
	function admin_type_del_do() 
	{ 
		global $mysql_conn;
		$type_id = $_POST['type_id'];
		$sql = "DELETE from `user_type` WHERE `type_id` = '".$type_id."'";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		echo "1";
	}
} 
/* End of file democontroller.php */ 